//新闻数据全部
var total;
var vals;
var pages = 1;
var emotion;
//新闻数据
$(function(){
		$('.attribute dd').click(function() {
		emotion = null;
		if($(this).index() == 2) {
			emotion = 1;
		} else if($(this).index() == 3) {
			emotion = 2;
		} else if($(this).index() == 4) {
			emotion = 0;
		}
		pages = 1;
		news($(this).index());
	});
});

function news(a,data) {
	vals = a;
	var data = JSON.stringify({
		'type': 3,
		'searchword': name,
		'pageNum': pages,
		'emotion':emotion,
		'pageSize': 10,
	});
	$.ajax({
		type: "post",
		url: 'http://139.224.208.224:8080/qi-radar/sensation/getSensation;',
		dataType: 'json',
		contentType: "application/json ",
		async: false,
		data: data,
		success: function(data) {
			if(data.code == 0) {
				var total = data.total;
				var data = data.data;
				console.log(data)
				var list = '';
				var carNewsList = ''
				var title = [];
				var from = [];
				var newTime = [];
				var year = [];
				var month = []
				var day = [];
				var time = [];
				var times = [];
				for(var i = 0; i < data.length; i++) {
					var carNewsList = '';
					$.each(data[i].keyword, function(i, item) {
						carNewsList += "<li>" + item.keyword_name + "</li>";
					});
					newTime.push(new Date(data[i].content_time))
					year.push(newTime[i].getFullYear());
					month.push(newTime[i].getMonth() + 1);
					day.push(newTime[i].getDate());
					time.push((year[i] + "-" + month[i] + "-" + day[i]));
					times.push(time[i]);
					if(vals == 1) {
							list += "<div class=\"neutral-list\" id=\"new-neutral\">";
							list += "<div class=\"forum_item neutral-part\">";
							list += "<div class=\"clearfix forum-header\">";
							if(data[i].emotion == 1) {
								list += "<div class=\"fl positive\">正</div>";
							} else if(data[i].emotion == 2) {
								list += "<div class=\"fl negative\">负</div>";
							} else {
								list += "<div class=\"fl neutral\">中</div>";
							}
							list += "<p class=\"fl item-content2\">";
							list += "<a href=\"#\">" + data[i].title + "</a>";
							list += "</p>";
							list += "<div class=\"forum_time fr grcolor\">" + times[i] + "</div>";
							list += "</div>";
							list += "<div class=\"face_forum_content\">" + data[i].summary + "</div>";
							list += "<div class=\"bottom-line\"></div>";
							list += "<div class=\"Thermal_index clearfix\">";
							list += "<div class=\"fl hot\">";
							list += "<div class=\"fl header-hot-txt grcolor\">热度指数</div>";
							list += "<div class=\"hot-progress fl\">";
							list += "<div class=\"progress-val\" id=\"bar_width\">" + data[i].heat_value + "</div>";
							list += "<div class=\"progress-bar\">";
							list += "<span class=\"progress-in\" id=\"bar\"></span>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
							list += "<div class=\"keyword fl\">";
							list += "<ul class=\"clearfix grcolor\">";
							list += "<li>关键词：</li>";
							list += carNewsList;
							list += "</ul>";
							list += "</div>";
							list += "<div class=\"fr grcolor\"><span>回答： </span><span>" + data[i].read_num + "</span></div>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
						} else if(vals == 2) {
							if(data[i].emotion == 1) {
								list += "<div class=\"positive-list\" id=\"new-positive\">";
								list += "<div class=\"forum_item neutral-part\">";
								list += "<div class=\"clearfix forum-header\">";
								list += "<div class=\"fl positive\">正</div>";
								list += "<p class=\"fl item-content2\">";
								list += "<a href=\"#\">" + data[i].title + "</a>";
								list += "</p>";
								list += "<div class=\"forum_time fr grcolor\">" + times[i] + "</div>";
								list += "</div>";
								list += "<div class=\"face_forum_content\">" + data[i].summary + "</div>";
								list += "<div class=\"bottom-line\"></div>";
								list += "<div class=\"Thermal_index clearfix\">";
								list += "<div class=\"fl hot\">";
								list += "<div class=\"fl header-hot-txt grcolor\">热度指数</div>";
								list += "<div class=\"hot-progress fl\">";
								list += "<div class=\"progress-val\" id=\"bar_width\">" + data[i].heat_value + "</div>";
								list += "<div class=\"progress-bar\">";
								list += "<span class=\"progress-in\" id=\"bar\"></span>";
								list += "</div>";
								list += "</div>";
								list += "</div>";
								list += "<div class=\"keyword fl\">";
								list += "<ul class=\"clearfix grcolor\">";
								list += "<li>关键词：</li>";
								list += carNewsList;
								list += "</ul>";
								list += "</div>";
								list += "<div class=\"fr grcolor\"><span>回答： </span><span>" + data[i].read_num + "</span></div>";
								list += "</div>";
								list += "</div>";
								list += "</div>";
						}
					}else if(vals == 3) {
//						if(data[i].emotion == 2) {
							list += "<div class=\"negative-list\" id=\"new-negative\">";
							list += "<div class=\"forum_item neutral-part\">";
							list += "<div class=\"clearfix forum-header\">";
							list += "<div class=\"fl negative\">负</div>";
							list += "<p class=\"fl item-content2\">";
							list += "<a href=\"#\">" + data[i].title + "</a>";
							list += "</p>";
							list += "<div class=\"forum_time fr grcolor\">" + times[i] + "</div>";
							list += "</div>";
							list += "<div class=\"face_forum_content\">" + data[i].summary + "</div>";
							list += "<div class=\"bottom-line\"></div>";
							list += "<div class=\"Thermal_index clearfix\">";
							list += "<div class=\"fl hot\">";
							list += "<div class=\"fl header-hot-txt grcolor\">热度指数</div>";
							list += "<div class=\"hot-progress fl\">";
							list += "<div class=\"progress-val\" id=\"bar_width\">" + data[i].heat_value + "</div>";
							list += "<div class=\"progress-bar\">";
							list += "<span class=\"progress-in\" id=\"bar\"></span>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
							list += "<div class=\"keyword fl\">";
							list += "<ul class=\"clearfix grcolor\">";
							list += "<li>关键词：</li>";
							list += carNewsList;
							list += "</ul>";
							list += "</div>";
							list += "<div class=\"fr grcolor\"><span>回答： </span><span>" + data[i].read_num + "</span></div>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
//						}
					}else if(vals == 4) {
						if(data[i].emotion == 0) {
							list += "<div class=\"neutral-list\" id=\"new-neutral\">";
							list += "<div class=\"forum_item neutral-part\">";
							list += "<div class=\"clearfix forum-header\">";
							list += "<div class=\"fl neutral\">中</div>";
							list += "<p class=\"fl item-content2\">";
							list += "<a href=\"#\">" + data[i].title + "</a>";
							list += "</p>";
							list += "<div class=\"forum_time fr grcolor\">" + times[i] + "</div>";
							list += "</div>";
							list += "<div class=\"face_forum_content\">" + data[i].summary + "</div>";
							list += "<div class=\"bottom-line\"></div>";
							list += "<div class=\"Thermal_index clearfix\">";
							list += "<div class=\"fl hot\">";
							list += "<div class=\"fl header-hot-txt grcolor\">热度指数</div>";
							list += "<div class=\"hot-progress fl\">";
							list += "<div class=\"progress-val\" id=\"bar_width\">" + data[i].heat_value + "</div>";
							list += "<div class=\"progress-bar\">";
							list += "<span class=\"progress-in\" id=\"bar\"></span>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
							list += "<div class=\"keyword fl\">";
							list += "<ul class=\"clearfix grcolor\">";
							list += "<li>关键词：</li>";
							list += carNewsList;
							list += "</ul>";
							list += "</div>";
							list += "<div class=\"fr grcolor\"><span>回答： </span><span>" + data[i].read_num + "</span></div>";
							list += "</div>";
							list += "</div>";
							list += "</div>";
						}
					}
				}
				$('.news-list').html(list);
				//判读数据是否过于十条
					if(total>10){
						$("#pageToolBox").show();
					};
					
				//分页多
				function paged() {
					$('#pageTool').empty();
					$('#pageTool').Paging({
						pagesize: 10,
						count: total,
						current: pages,
						callback: function(page, size, count) {
							pages = page;
							news(vals);
						}
					});
				};
				paged();
				
			}
		}
	});
};